<div class="container-fluid">
    <h4>用户信息</h4>
    <div class="table-wrapper users-table section">
        <div class="row-fluid head">
        </div>

        <div class="input-group" id="search">
            &nbsp;<label for="realname">姓名：</label>
            <input type="text" name="realname" class="input-small" id="realname">
            <label for="mobile">&nbsp;电话：</label>
            <input type="text" name="mobile" class="input-small" id="mobile">
            <span>
           <button id="search_btn" type="button" class="btn btn-purple btn-sm">
               搜索
               <i class="icon-search icon-on-right bigger-110"/>
           </button>
       </span>
        </div>
        <div id="list"></div>
    </div>
</div>

<script>
    (function () {
        var url = 'user/list-data.do';
        var $datagrid = $('#list');

        loadData();

        $('#search_btn').on('click', function () {
            loadData();
        });

        function loadData() {
            $datagrid.datagrid({
                action: true,
                doUpdate: function (rowData) {
                    doUpateData(rowData.id);
                },
                doDel: function () {
                    layer.msg("不允许删除用户信息", {icon: 1});
                },
                'dataModel': {
                    'url': url,
                    'parameters': getCommJosnParams('search')
                },
                'columns': [
                    {title: '姓名', dataField: 'realname'},
                    {title: '电话', dataField: 'mobile'},
                    {title: '角色', dataField: 'roleName'},
                    {title: '注册时间', dataField: 'createTime'}
                ]
            });
        };

        function doUpateData(id) {
            var $div = $('<div>');
            $div.load('user/form.do?id=' + id, function (response, status, xhr) {
                if (xhr.status == 200) {
                    layer.open({
                        type: 1,//Page层类型
                        area: ['300px', '250px'],
                        title: '修改用户信息',
                        btn: ['提交修改'],
                        content: $div.html(),
                        yes: function (layId) {
                            var param = $('#formUserModify').serialize();
                            $.post('user/update.do', param, function (result) {
                                if (result.success) {
                                    loadData();
                                    layer.msg('修改成功', {icon: 1});
                                    layer.close(layId)
                                } else {
                                    layer.msg('修改失败', {icon: 5});
                                }
                            }, 'json')
                        }
                    });
                }
            });
        }

    })();
</script>
